﻿package effects
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.*;
	import flash.geom.Point;
	import Global;	
	public class Effect5 extends Effect
	{
		private var max:int=10;
		public var count:int=0;
		private var bColor:uint = 0x000000;
		private var dots:Sprite = new Sprite;
		
		private var points:Sprite;
		public function Effect5()
		{	
			graphics.beginFill(bColor,1);
			graphics.drawRect(0,0,Global._stage.stageWidth,Global._stage.stageHeight);
			graphics.endFill();
			dots.filters=[new BlurFilter(33,33,1),
			new GlowFilter(Math.random()*0x444444,1,24,24,2,1,true)];
			addChild(dots);
			addEventListener(Event.ENTER_FRAME,draw);
		}
		public override function add():void
		{
			addEventListener(Event.ENTER_FRAME,draw);
		}
		public override function remove():void
		{
			removeEventListener(Event.ENTER_FRAME,draw);
		}
		private function draw(e:Event):void
		{
			if(count==0)
			{
				dots.filters=[new BlurFilter(33,33,1),
				new GlowFilter(Math.random()*0xffcc00,1,15,15,2,1,true,false)];
			}
			if(count<max){
				var dot:Dot = new Dot(this);
				dots.addChild(dot);			
				count++;
			}
		}
	}
}
//helper classes
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import Global;
import effects.Effect;
import flash.events.Event;
import flash.geom.Point;
	
class Dot extends Sprite{
	private var clr:uint = Math.random()*0xff0000;
	private var size:int = 150;
	
	private var a:uint = 1;
	private var dirx:Boolean = false;
	private var diry:Boolean = false;
	private var dx:int;
	private var dy:int;
	private var ds:int;
	private var dumm:Sprite;
	
	private var p:*;
	public function Dot(_p:*)
	{
		p=_p;
		x=Global.rrnd(0,Global._stage.stageWidth);
		y=Global.rrnd(0,Global._stage.stageHeight);
		dx=Global.rrnd(0,Global._stage.stageWidth);
		dy=Global.rrnd(0,Global._stage.stageHeight);
		scaleX=scaleY=0;
		ds=Math.random()+.8;
		
		draw();
	}
	private function draw():void
	{
		blendMode="add";
		cacheAsBitmap=true;
		
		var dx:int;
		var dy:int;

		/*
		switch (x)
		
		{
			case x<Global._stage.stageWidth/2:
			x=0-Global._stage.stageWidth*14;//dx=Global._stage.stageWidth/2;//Global.rrnd(-Global._stage.stageWidth*2,-Global._stage.stageWidth/2)
			break;
			case x>Global._stage.stageWidth/2:
			x=x-Global._stage.stageWidth*14;//dx=Global._stage.stageWidth/2;//Global.rrnd(Global._stage.stageWidth/2,Global._stage.stageWidth*2)
			break;
		}
		switch (y)
		{
			case y<Global._stage.stageHeight/2:
			y-=Global._stage.stageHeight*2;//dy=Global._stage.stageHeight/2;//Global.rrnd(-Global._stage.stageHeight*2,-Global._stage.stageHeight/2)
			break;
			case y>Global._stage.stageWidth/2:
			y+=Global._stage.stageHeight*2;
			break;
		}
		*/
		graphics.beginFill(clr,a);
		graphics.drawCircle(0,0,size);
		graphics.endFill();
		addEventListener(Event.ENTER_FRAME,move);		
	}
	private function open(e:Event):void
	{
		alpha+=(1-alpha)/16;
		if(alpha>=1)
		{
			dumm.removeEventListener(Event.ENTER_FRAME,open);
			removeChild(dumm);
		}
	}
	private function move(e:Event):void
	{
		x+=(dx-x)/64;
		y+=(dy-y)/64;
		scaleX+=(ds-scaleX)/64;
		scaleY+=(ds-scaleY)/64;
		
		if((dirx && x>=dx && diry && y>=dy) || (!dirx && x<=dx && !diry && y<=dy) || (dirx && x>=dx && !diry && y<=dy) || (!dirx && x<=dx && diry && y>=dy))
		{
			removeEventListener(Event.ENTER_FRAME,move);
			addEventListener(Event.ENTER_FRAME,kill);
			//parent.removeChild(this);
		}
	}
	private function kill(e:Event):void
	{
		alpha-=.3;
		if(alpha<=0)
		{
			removeEventListener(Event.ENTER_FRAME,kill);
			p.count--;
			parent.removeChild(this);
		}
	}
}